package com.example.hellonotes.adapter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.example.hellonotes.R;
import com.example.hellonotes.R.id;
import com.example.hellonotes.R.layout;
import com.example.hellonotes.utils.GetThumbnail;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NotesAdapter extends BaseAdapter{

	private Context context;
	private Cursor cursor;
	private LinearLayout layout;
	final int TYPE_1 = 0;  
    final int TYPE_2 = 1;
    private int TYPE;
    private String path;
    private ArrayList<Uri> imgUriss = new ArrayList<Uri>();
	
	public NotesAdapter(Context context,Cursor cursor) {
		this.context = context;
		this.cursor = cursor;
	}
	
	@Override
	public int getCount() {
		return cursor.getCount();       //返回cursor数据的长度
	}

	@Override
	public Object getItem(int position) {
		return cursor.getPosition();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LayoutInflater inflater = LayoutInflater.from(context);
		layout = (LinearLayout) inflater.inflate(R.layout.cell, null);
		TextView contentTV = (TextView) layout.findViewById(R.id.list_content);
		TextView timeTV = (TextView) layout.findViewById(R.id.list_time);
		ImageView imgIV = (ImageView) layout.findViewById(R.id.list_img);
		cursor.moveToPosition(position);
		String content = cursor.getString(cursor.getColumnIndex("content"));
		String time = cursor.getString(cursor.getColumnIndex("time"));
		String path = cursor.getString(cursor.getColumnIndex("path"));  /////草 一下午就一個大小寫的問題
		contentTV.setText(content);
		timeTV.setText(time);
		String uris = path.substring(1, path.length()-1);
		String[] uri = uris.split(",");
		ImageLoader.getInstance().displayImage(uri[0], imgIV);
		return layout;
	}
	
	}


